package com.zx.mq.pubsub;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class PubSubConfigure {

    // 新建三个队列
    @Bean
    public Queue AQueue(){
        return new Queue("fanout.A");
    }
    @Bean
    public Queue BQueue(){
        return new Queue("fanout.B");
    }
    @Bean
    public Queue CQueue(){
        return new Queue("fanout.C");
    }

    // 交换机
    @Bean
    FanoutExchange fanoutExchange() {
        return new FanoutExchange("fanoutExchange");
    }

    // 队列绑定到交换机:AQueue为上面定义的bean
    @Bean
    Binding bindingExchangeA(Queue AQueue, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(AQueue).to(fanoutExchange);
    }

    @Bean
    Binding bindingExchangeB(Queue BQueue, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(BQueue).to(fanoutExchange);
    }

    @Bean
    Binding bindingExchangeC(Queue CQueue, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(CQueue).to(fanoutExchange);
    }

}
